package cn.lijiguo.concurrency.part1.ch04;

/**
 * DaemonThread2
 *
 * @author lijiguo
 * @date 2019/12/13 12:56
 */
public class DaemonThread2 {

    public static void main(String[] args) {
        Thread t = new Thread() {
            @Override
            public void run() {

                // 线程中创建子线程
                Thread innerThread = new Thread() {
                    @Override
                    public void run() {
                        while(true) {
                            System.out.println("innerThread...");
                            try {
                                Thread.sleep(10_000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                };

                // 将线程设置为守护线程
                innerThread.setDaemon(true);
                innerThread.start();


                try {
                    Thread.sleep(1000);
                    System.out.println("主线程结束。。。");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        t.start();
    }
}
